package fr.jade.service.fm.deployment;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalContentException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;

import fr.jade.base.JadeBaseObject;
import fr.jade.reflex.util.Reflex;

public class CleanFatherTask extends JadeBaseObject implements DeploymentTask {

  protected Component father;
  protected Component child;
  
  public CleanFatherTask(Component father, Component child){
    this.father=father;
    this.child=child;
  }
  
  public void execute() throws DeploymentException {
    log("execute :" +toString());
    
    try {
      Reflex.getContentNotificationController(father).rawRemoveFcSubComponentNotification(child);
      Reflex.getContentNotificationController(Reflex.getDualComponent(father)).rawRemoveFcSubComponentNotification(Reflex.getDualComponent(child));
    } catch (IllegalContentException e) {
      throw new DeploymentException("can't clean father", e);
    } catch (IllegalLifeCycleException e) {
      throw new DeploymentException("can't clean father", e);
    } catch (NoSuchInterfaceException e) {
      throw new DeploymentException("can't clean father", e);
    }
  }
  
  public String getLevelName(){
    return "cleanContent";
  }
  
  public String toString(){
    return "CleanFatherTask[father:"+father+" - child:"+child+"]";
  }

}
